const path = require('path')
const IS_PROD = ['prod', 'production'].includes(process.env.NODE_ENV)
const resolve = dir => path.join(__dirname, dir)

module.exports = {
  publicPath: './',
  productionSourceMap: !IS_PROD,
  lintOnSave: false,
  chainWebpack: config => {
    config.resolve.alias
      .set('@', resolve('./src'))
      .set('assets', resolve('./src/assets'))
      .set('components', resolve('./src/components'))
      .set('router', resolve('./src/router'))
      .set('tools', resolve('./src/Tools'))
      .set('store', resolve('./src/store'))
    // 1. 取消默认 file-loader 对 svg 文件的处理
    config.module
      .rule('svg') // 对 svg 规则的配置
      .exclude // 添加忽略文件夹
      .add(resolve('./src/assets/icons/svg')) // 绝对路径
      .end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include
      .add(resolve('./src/assets/icons/svg'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()
  },
  css: {
    loaderOptions: {
      sass: {
        prependData: `@import "@/assets/style/_variable.scss";`
      }
    }
  }
}
